﻿using System;
using System.Collections.Generic;
using AutoMapper;
using CodeSaude.Application.Interfaces;
using CodeSaude.Application.ViewModels;
using CodeSaude.Domain.Entities;
using CodeSaude.Domain.Interfaces.Service;

namespace CodeSaude.Application.Services
{
    public class OxigenoterapiaApplicationService : BaseApplicationService,  IOxigenoterapiaApplicationService
    {
        private readonly IOxigenoterapiaService _oxigenoterapiaService;

        public OxigenoterapiaApplicationService(IOxigenoterapiaService oxigenoterapiaService)
        {
            _oxigenoterapiaService = oxigenoterapiaService;
        }

        public void Add(OxigenoterapiaViewModel oxigenoterapiaViewModel)
        {
            var oxigenoterapia = Mapper.Map<OxigenoterapiaViewModel, Oxigenoterapia>(oxigenoterapiaViewModel);

            BeginTransaction();
            _oxigenoterapiaService.AdicionarOxigenoterapia(oxigenoterapia);
            Commit();
        }

        public OxigenoterapiaViewModel GetById(int id)
        {
            return Mapper.Map<OxigenoterapiaViewModel>(_oxigenoterapiaService.GetById(id));
        }

        public IEnumerable<OxigenoterapiaViewModel> GetAll()
        {
            return Mapper.Map<IEnumerable<OxigenoterapiaViewModel>>(_oxigenoterapiaService.GetAll());
        }

        public void Update(OxigenoterapiaViewModel oxigenoterapiaViewModel)
        {
            var oxigenoterapia = Mapper.Map<Oxigenoterapia>(oxigenoterapiaViewModel);

            BeginTransaction();
            _oxigenoterapiaService.Update(oxigenoterapia);
            Commit();
        }

        public void Remove(OxigenoterapiaViewModel oxigenoterapiaViewModel)
        {
            var user = _oxigenoterapiaService.GetById(oxigenoterapiaViewModel.OxigenoterapiaId);
            BeginTransaction();
            _oxigenoterapiaService.Remove(user);
            Commit();
        }

        public void Dispose()
        {
            _oxigenoterapiaService.Dispose();
        }
    }
}
